<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">应急上报种类</label>
        <div class="layui-input-block">
            <div id="reportspeciesId"></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">发生情况</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入发生情况" class="layui-textarea" name="occurrence" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">事件时间</label>
        <div class="layui-input-block">
            <input type="text" name="eventtime" id="eventtimeId" placeholder="请选择事件时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">地点</label>
        <div class="layui-input-block">
            <input name="place" class="layui-input" placeholder="请输入地点" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">单位</label>
        <div class="layui-input-block">
            <input name="unit" class="layui-input" placeholder="请输入单位" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">简要经过</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入简要经过" class="layui-textarea" name="afterbriefly" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item" style="display:none" id="casualty">
        <label class="layui-form-label layui-form-required">伤亡人数</label>
        <div class="layui-input-block">
            <input name="casualty" type="number" class="layui-input" placeholder="请输入伤亡人数" lay-verType="tips" required/>
        </div>
    </div>

    <div class="layui-form-item" style="display:none" id="economicloss">
        <label class="layui-form-label layui-form-required">直接经济损失（估算）</label>
        <div class="layui-input-block">
            <input name="economicloss" class="layui-input" placeholder="请输入直接经济损失（估算）" lay-verType="tips" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">发生原因（初步判断）</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入发生原因（初步判断）" class="layui-textarea" name="reason" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">先期处置措施</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入先期处置措施" class="layui-textarea" name="measure" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">下一步处置措施</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入下一步处置措施" class="layui-textarea" name="nextmeasure" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">事故控制情况</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入事故控制情况" class="layui-textarea" name="controlaccident" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">未来走势预测</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入未来走势预测" class="layui-textarea" name="forecastfuture" lay-verify="required" required></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">报送单位</label>
        <div class="layui-input-block">
            <input name="sendunit" class="layui-input" placeholder="请输入报送单位" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">签发人</label>
        <div class="layui-input-block">
            <input name="signer" class="layui-input" readonly="true"  style="background:#CCCCCC" placeholder="请输入签发人" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">联系人</label>
        <div class="layui-input-block">
            <input name="contact" class="layui-input" placeholder="请输入联系人" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">联系电话</label>
        <div class="layui-input-block">
            <input name="phone" class="layui-input" placeholder="请输入联系电话" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;
        $.get(getProjectUrl() +"getLoginUser",function(res){
            $('[name="signer"]').val(res.data.name);
            if (res.data.name.includes("管理员")){
                 $("#casualty").show();
                 $("#economicloss").show();
            }
        })
        var reportspeciesRenderIns = xmSelect.render({
            el: '#reportspeciesId',
            name: 'reportspecies',
            data: xnUtil.getDictDataByDictTypeCode('emergencyreporttypes', null),
            layVerify: 'required',
            layVerType: 'tips',
            radio: true,
            clickClose: true,
            model: { icon:'hidden', label: { type: 'text' }},
            prop: {
                name: 'name',
                value: 'code'
            },
            tips: '请选择应急上报种类'
        }, {async: false});

        laydate.render({
            elem: '#eventtimeId'
        });

        var editData = admin.getLayerData('#addOrUpdateForm').data;
        if(editData !== null && editData !== undefined) {
            form.val('addOrUpdateForm', editData);
            // 下拉赋值
            reportspeciesRenderIns.setValue([editData.reportspecies]);

        }

        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            layer.load(2);

            var url = editData ? getProjectUrl() + 'report/edit' : getProjectUrl() + 'report/add';
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });
    });
</script>
</body>
</html>
